#!/usr/bin/pypy

# BigData course project
# Serial version of training algorithm for SOM
# Main module

import sys
from trainset import TrainSet
from som import SOM
from util import *

if len(sys.argv) != 12:
    log("Usage: %s <dim> <ts_size> <ts_file> <size_x> <size_y> " +
        "<min_w> <max_w> <som_file_ini> <som_file_fin> <debug> " + 
        "<show_progress>", sys.argv[0])
    sys.exit(1)

dim = int(sys.argv[1])
ts_size = int(sys.argv[2])
ts_file = sys.argv[3]
size_x = int(sys.argv[4])
size_y = int(sys.argv[5])
min_w = float(sys.argv[6])
max_w = float(sys.argv[7])
som_file_ini = sys.argv[8]
som_file_fin = sys.argv[9]
debug = int(sys.argv[10])
show_progress = int(sys.argv[11])

ts = TrainSet(dim, ts_size, ts_file)
som = SOM(ts, size_x, size_y, min_w, max_w)
log("dumping initial som ... \n")
som.dump(som_file_ini)
som.learn(show_progress)
log("dumping final som ... \n")
som.dump(som_file_fin)
